package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    // /baseTrademark/1/10

    /**
     * 品牌分页查询
     * @param pn
     * @param ps
     * @return
     */
    @GetMapping("/baseTrademark/{pn}/{ps}")
    public Result baseTrademarkList(@PathVariable("pn") Long pn,
                                    @PathVariable("ps") Long ps){
        Page<BaseTrademark> page = new Page<>(pn,ps);
        //分页查询
        Page<BaseTrademark> result = baseTrademarkService.page(page);
        return Result.ok(result);
    }

    /**
     * 删除品牌信息
     * baseTrademark/save
     * @param baseTrademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    // /baseTrademark/remove/13

    /**
     * 根据品牌id删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result baseTrademarkDelete(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 获取品牌byId
     * @param id
     * @return
     */
    @GetMapping("baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable("id")Long id){
        BaseTrademark trademark = baseTrademarkService.getById(id);
        return Result.ok(trademark);
    }

    /**
     * 更新品牌信息
     * @param baseTrademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result UpdateBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 获取所有品牌
     * @return
     */
    ///baseTrademark/getTrademarkList
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
